$(function () { 
/* 监听游戏规则按钮 */
    $(".rules").click(function () { 
        $(".rule").stop().fadeIn(1000)
    })

/* 监听游戏规则关闭按钮 */
    $(".rule_btn").click(function () { 
        $(".rule").stop().fadeOut(1000)
    })

/* 监听开始游戏按钮 */
    $(".btn").click(function () { 
        $(this).stop().fadeOut(100, function () { 
            $(".fs").text("0")
            ProgressBar()
            appear()
        })
    })

/* 监听重新开始按钮 */
    $(".mask_btn").click(function () { 
        $(".mask").fadeOut(500, function () { 
            $(".fs").text("0")
            $(".btn").fadeOut(10)
            ProgressBar()     
            appear()
        })
    })

/* 监听返回按钮 */
    $(".goBack").click(function () { 
        $(".mask").stop().fadeOut(500)
        $(".btn").stop().fadeIn(500)
    })
    
    
    // 监听进度条
    function ProgressBar() { 
        $(".Progress").css({
            "width":180
        })
        var timer = setInterval(function () { 
            var sl = $(".Progress").width(); //180
            sl = sl - 1;
            if (sl <= 0) {
                clearInterval(timer)
                $(".mask").stop().fadeIn(1000)
                $(".df").text($(".fs").text())
                clearTimeout(woTimer)
                $(".dh_img").remove()
            } else { 
                $(".Progress").css({
                    "width":sl
                })
            }
        },100)
    }
    var woTimer;
    // 监听出现的页面
    function appear() { 
        var huitailang = [
            "./img/h0.png",
            "./img/h1.png",
            "./img/h2.png",
            "./img/h3.png",
            "./img/h4.png",
            "./img/h5.png",
            "./img/h6.png",
            "./img/h7.png",
            "./img/h8.png",
            "./img/h9.png",
        ];
        var xiaohuihui = [
            "./img/x0.png",
            "./img/x1.png",
            "./img/x2.png",
            "./img/x3.png",
            "./img/x4.png",
            "./img/x5.png",
            "./img/x6.png",
            "./img/x7.png",
            "./img/x8.png",
            "./img/x9.png",
        ];
        var arrPos = [
            {left:"100px",top:"115px"},
            {left:"20px",top:"160px"},
            {left:"190px",top:"142px"},
            {left:"105px",top:"193px"},
            {left:"19px",top:"221px"},
            {left:"202px",top:"212px"},
            {left:"120px",top:"275px"},
            {left:"30px",top:"295px"},
            {left:"209px",top:"297px"}
        ];

        var img = $("<img class='dh_img' src=''/>")
        var sj = Math.round(Math.random() * 8);
        var lx = Math.round(Math.random());
        
        if (lx == 0) {
            // img.attr("src", huitailang[5])
            li=huitailang
        } else { 
            // img.attr("src",xiaohuihui[5])
            li=xiaohuihui
        }
        window.minindex = 0;
        window.maxindex=5
         woTimer = setInterval(() => {
            if (minindex >= maxindex) {
                img.remove()
                clearTimeout(woTimer)
                appear()
            } else { 
                img.attr("src", li[minindex])
            }
            minindex++
        }, 150);

        img.css({
            position: "absolute",
            left: arrPos[sj].left,
            top: arrPos[sj].top
        })

        $(".content").append(img)

        gameRules(img);
    }
    function gameRules(img){
          /* 监听图片点击 */
        img.one("click", function () {
              
        window.minindex=5;
        window.maxindex=10;

        var src=$(this).attr("src")
            var flag = src.indexOf("h");
            console.log(flag);
            if(flag>0){
            $(".fs").text( parseInt($(".fs").text())+10)
            }else{
            $(".fs").text( parseInt($(".fs").text())-10)
            }
        })
    }


  
})